package org.egedede.osgi.guishell.actions;

import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Properties;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

import org.egedede.osgi.guishell.model.Command;

public class InstallAction extends AbstractAction {

	private Command installCommand;

	public InstallAction(){
		super("Install");
	}

	public void actionPerformed(ActionEvent e) {
		JFileChooser chooser = new JFileChooser();
		chooser.setFileFilter(new FileFilter(){

			@Override
			public boolean accept(File f) {
				return f.getName().endsWith(".jar")|| f.isDirectory();
			}

			@Override
			public String getDescription() {

				return "Bundle files";
			}

		});
		int result = chooser.showOpenDialog(null);
		if(result==JFileChooser.APPROVE_OPTION){
			File file = chooser.getSelectedFile();
			Properties props = new Properties();
			props.put("bundle.file", file);
			installCommand.execute(props, System.out, System.err);
		}else{
			System.out.println("oups");
		}

	}
	public Command getInstallCommand() {
		return installCommand;
	}
	public void setInstallCommand(Command installCommand) {
		this.installCommand = installCommand;
	}



}
